home *** CD-ROM | disk | FTP | other *** search
- Path: news.mira.net.au!news
- From: davidw@werple.net.au (David White)
- Newsgroups: comp.lang.c++
- Subject: Re: Is this a memory leak?
- Date: 5 Apr 1996 21:34:28 +1000
- Organization: Werple Internet, Melbourne
- Message-ID: <4k30g4$sdo@werple.net.au>
- References: <4jv214$gv7@insosf1.netins.net> <4k114a$m5d@linet06.li.net>
- NNTP-Posting-Host: werplez.mira.net.au
-
- jeremy@newshost.li.net (Jeremy Markman) writes:
-
- >Harold Howe (hhowe@trgnet.com) wrote:
- >: Could someone please tell me if this code leaks memory
-
-
- >: public:
- >: TopClass::TopClass() { bury = new BuriedClass();}
- >: shutDown { bury = 0;}
- >: ~TopClass { delete bury}
-
- >: Is the memory that was alloced for the buried class lost? If not please
- >: describe how it was freed. Does zeroing the pointer free the memory? The
- >: delete is a waste of time on a zeroed pointer, isn't it.
-
- >Yes, your are correct. By assigning bury to 0, you are effectively
- >reassigning the memory pointer to NULL. Therefore, deleting bury has no
- >effect. The shutdown function is not necessary, in fact, it is bad
- >practice to do that. Just the delete bury is necessary, and if you do
- >want to assign 0 to a pointer, use NULL.
-
- The shutdown function does seem unusual practice, but surely whether it is
- bad practice in the context of its use depends on its purpose, which has
- not been established.
-
- Also, many prominent people involved in C++, among them Bjarne Stroustrup,
- the language's designer, recommend using 0, not NULL, as a null pointer.
- One of the arguments against NULL is that it is not as portable as 0; some
- people might spell it 'Null', or 'null'.
-
- >More explanation:
- >new allocattes memory and delete deallocates it. If you change the
- >pointer to that it does not point to the allocated memory, it can't
- >deallocate it, now can it?
-
- >Hope this helps...
-
- David White
- davidw@werple.mira.net.au
-